package com.franz.noteapp.useCase

import com.franz.noteapp.bean.InvalidNoteException
import com.franz.noteapp.bean.NoteBean
import com.franz.noteapp.room.repository.NoteRepository
import java.io.InvalidClassException
import kotlin.jvm.Throws

class InsertNote(private val repository: NoteRepository) {

    @Throws(InvalidNoteException::class)
    suspend operator fun invoke(bean: NoteBean){
        if (bean.title.isBlank()){
            throw InvalidNoteException("标题不能为空!")
        }
        if (bean.content.isBlank()){
            throw InvalidNoteException("内容不能为空!")
        }
        repository.insertNote(bean)
    }
}